//
//  ST_ExchangeBindStepItemView.swift
//  btvideo
//
//  Created by Jason on 2021/10/13.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift

class ST_ExchangeBindStepItemView: UIView {
    
    init(number:Int,title:String){
        super.init(frame: .zero)
        
        self.addSubview(number_label)
        number_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.height.equalTo(28)
            make.top.equalToSuperview()
        }
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.height.equalTo(18)
            make.bottom.equalToSuperview()
        }
        
        number_label.text = number.string
        
        titleLabel.text = title
        
        binding()
    }
    
    fileprivate func binding(){
        
        isHighlight.subscribe(onNext: {[weak self] f in
            
            let color = f ? self?.highlightColor : self?.normalColor
            
            self?.number_label.textColor = color
            self?.number_label.borderColor = color
            self?.number_label.borderWidth = 2
            
            self?.titleLabel.textColor = color
            
        }).disposed(by: dispostBag)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 高亮
    let isHighlight = BehaviorRelay<Bool>(value: false)
    
    
    var dispostBag = DisposeBag()
    
    fileprivate let normalColor = UIColor(hex: 0xD8D8D8)
    
    fileprivate let highlightColor = UIColor(hex: 0x24DA4C)
    
    fileprivate lazy var number_label:UILabel = {
        let l = UILabel()
        l.font = .systemFont(ofSize: 15, weight: .medium)
        l.textAlignment = .center
        l.cornerRadius = 28/2.0
        return l
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let l = UILabel()
        l.font = .systemFont(ofSize: 13, weight: .medium)
        l.textAlignment = .center
        return l
    }()
    
}


class ST_ExchangeBindStepItemLine: UIView {
    
    override init(frame: CGRect){
        super.init(frame: frame)
        
        isHighlight.subscribe(onNext: {[weak self] f in
            
            let color = f ? self?.highlightColor : self?.normalColor
            self?.backgroundColor = color
            
        }).disposed(by: dispostBag)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 高亮
    let isHighlight = BehaviorRelay<Bool>(value: false)
    
    var dispostBag = DisposeBag()
    
    fileprivate let normalColor = UIColor(hex: 0xD8D8D8)
    
    fileprivate let highlightColor = UIColor(hex: 0x24DA4C)
}
